﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;
using System.Collections;

namespace WXYW
{
    public partial class UpgradeNeedSendBack : System.Web.UI.Page
    {
        public int RecordsNumber { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindForms();
            }
        }

        protected void upgradeFormsGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            if (e.NewPageIndex >= 0 && e.NewPageIndex < upgradeFormsGridView.PageCount)
            {
                upgradeFormsGridView.PageIndex = e.NewPageIndex;
                BindForms();
            }
        }

        protected void updateLinkButton_Click(object sender, EventArgs e)
        {
            string upID = ((LinkButton)sender).CommandArgument;
            Response.Redirect(string.Format("UpgradeSendback.aspx?{0}={1}", Constants.QUERYSTR_UPGRADE_ID, upID));
        }

        private void BindForms()
        {
            UpgradeService service = new UpgradeService();
            List<UpgradeForm> forms = service.GetUpgradeFormByStatus("升级-完毕待发货");
            RecordsNumber = forms.Count;
            upgradeFormsGridView.DataSource = forms;
            upgradeFormsGridView.DataBind();
        }

        protected void upgradeFormsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                ((Label)e.Row.FindControl("IDLbl")).Text = (e.Row.RowIndex + 1).ToString();
            }

            if (e.Row.RowType == DataControlRowType.Pager)
            {
                DropDownList pageDDL = e.Row.FindControl("pageDDL") as DropDownList;
                for (int index = 1; index <= upgradeFormsGridView.PageCount; index++)
                {
                    pageDDL.Items.Add(index.ToString());
                }
                pageDDL.SelectedValue = (upgradeFormsGridView.PageIndex + 1).ToString();
            }
        }

        protected IEnumerable GridView_MustAddARow(IEnumerable data)
        {
            List<UpgradeForm> dds = new List<UpgradeForm>();
            dds.Add(new UpgradeForm());
            return dds;
        }

        protected void pageDDL_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList pageDDL = sender as DropDownList;
            upgradeFormsGridView.PageIndex = Convert.ToInt32(pageDDL.SelectedIndex);
            BindForms();
        }

        protected void upgradeFormsGridView_DataBound(object sender, EventArgs e)
        {
            if (upgradeFormsGridView.BottomPagerRow != null)
            {
                upgradeFormsGridView.BottomPagerRow.Visible = true;
            }
        }
    }
}
